package ch.sfug.graphics.primitives {
	import flash.display.Shape;
	import flash.display.Sprite;	

	public class SimpleTriangle extends Sprite {
		private var _widthRect;
		private var _heightRect;
		private var _triangle:Shape;

		public function SimpleTriangle(color:Number = 0x000000, widthRect:Number = 25, heightRect:Number = 25, alphaVal:Number = 1, direction:String = "right") {
			_widthRect = widthRect;
			_heightRect = heightRect;
			
			setUI(color, alphaVal, direction);
		}

		
		private function setUI(color, alphaVal, direction):void {
			alpha = alphaVal;
	       	
			_triangle = new Shape();
			_triangle.graphics.beginFill(color);
	        
			_triangle.graphics.moveTo(0, 0);
			_triangle.graphics.lineTo(_widthRect, _heightRect / 2);
			_triangle.graphics.lineTo(0, _heightRect);
			_triangle.graphics.lineTo(0, 0);
			
			addChild(_triangle);
			    
			setDirection(direction);
		}

		
		public function setDirection( direction:String ):void {
			switch( direction ) {
				case "left":
					_triangle.rotation = 180;
					_triangle.x = _widthRect;								
					_triangle.y = _heightRect;								
					break;
				
				case "up":
					_triangle.rotation = -90;												
					_triangle.y = _widthRect;							
					break;
				
				case "down":
					_triangle.rotation = 90;													
					_triangle.x = _heightRect;																												
					break;
				
				default:								
					_triangle.rotation = 0;								
					_triangle.x = 0;								
			}
		}
	}
}